<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="课表id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="courseArrangeId">
              <a-input v-model="model.courseArrangeId" placeholder="请输入课表id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teachingJobExeDate">
              <j-date placeholder="请选择日期" v-model="model.teachingJobExeDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="周次表示第几周" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="weekSetIndex">
              <a-input-number v-model="model.weekSetIndex" placeholder="请输入周次表示第几周" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="实际星期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teachingJobExeWeek">
              <a-input-number v-model="model.teachingJobExeWeek" placeholder="请输入实际星期" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="执行星期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teachingJobExeNewWeek">
              <a-input-number v-model="model.teachingJobExeNewWeek" placeholder="请输入执行星期" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="节次" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teachingJobExeSection">
              <a-input-number v-model="model.teachingJobExeSection" placeholder="请输入节次" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="课时量(上课持续时长)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teachingJobExeDuration">
              <a-input-number v-model="model.teachingJobExeDuration" placeholder="请输入课时量(上课持续时长)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="老师id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teacherId">
              <a-input v-model="model.teacherId" placeholder="请输入老师id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="科目id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="subjectId">
              <a-input v-model="model.subjectId" placeholder="请输入科目id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="教室id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="classroomId">
              <a-input v-model="model.classroomId" placeholder="请输入教室id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="班级id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="classId">
              <a-input v-model="model.classId" placeholder="请输入班级id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="上课状态（1正常，21代出课 22代入课(insert)，31交换出 32交换入）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teachingJobExeStatus">
              <a-input v-model="model.teachingJobExeStatus" placeholder="请输入上课状态（1正常，21代出课 22代入课(insert)，31交换出 32交换入）"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="代换课引用教学任务数据id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="quoteTeachingJobId">
              <a-input v-model="model.quoteTeachingJobId" placeholder="请输入代换课引用教学任务数据id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否启用(1是启用，0否停用)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="izOpen">
              <a-input-number v-model="model.izOpen" placeholder="请输入是否启用(1是启用，0否停用)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="学校id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenantId">
              <a-input v-model="model.tenantId" placeholder="请输入学校id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="0表示未删除,1表示删除" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="delFlag">
              <a-input-number v-model="model.delFlag" placeholder="请输入0表示未删除,1表示删除" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'CouTeachingJobExecuteForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           izOpen: [
              { required: true, message: '请输入是否启用(1是启用，0否停用)!'},
           ],
           delFlag: [
              { required: true, message: '请输入0表示未删除,1表示删除!'},
           ],
        },
        url: {
          add: "/couteachingjobexecute/couTeachingJobExecute/add",
          edit: "/couteachingjobexecute/couTeachingJobExecute/edit",
          queryById: "/couteachingjobexecute/couTeachingJobExecute/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>